-
Notifications
You must be signed in to change notification settings - Fork 292
mcp: handle bad or missing params #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
mcp/shared.go
Outdated
| if req.ID.IsValid() { | ||
| return methodInfo{}, fmt.Errorf("%w: unexpected id for %q", jsonrpc2.ErrInvalidRequest, req.Method) | ||
| } | ||
| } else if !req.ID.IsValid() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the logic is harder to follow with this change. I think the 2 un-nested if statements was easier to read. (But up to you)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point; unnested.
(also fixed the id/ID inconsistency in these messages)
Audit all cases where params must not be null, and enforce this using methodInfo via a new methodFlags bitfield that parameterizes method requirements. Write extensive conformance tests catching all the (server-side) crashes that were possible. We should go further and validate schema against the spec, but that is more indirect, more complicated, and potentially slower. For now we adopt this more explicit approach. Still TODO in a subsequent CL: verify the client side of this with client conformance tests. Additionally, improve some error messages that were redundant or leaked internal implementation details. Fixes modelcontextprotocol#195
Complements the methodFlags system from modelcontextprotocol#210 with additional unit tests: - Tests nil RawMessage and explicit JSON null handling in unmarshalParams - Tests edge cases with different JSON types (empty string, array, number, boolean) - Validates proper error handling for required vs optional params with methodFlags - Provides focused unit test coverage alongside existing conformance tests The tests verify that the panic vulnerability from modelcontextprotocol#186 is properly handled by the upstream methodFlags implementation.
Complements the methodFlags system from modelcontextprotocol#210 with additional unit tests: - Tests nil RawMessage and explicit JSON null handling in unmarshalParams - Tests edge cases with different JSON types (empty string, array, number, boolean) - Validates proper error handling for required vs optional params with methodFlags - Provides focused unit test coverage alongside existing conformance tests The tests verify that the panic vulnerability from modelcontextprotocol#186 is properly handled by the upstream methodFlags implementation.
Audit all cases where params must not be null, and enforce this using methodInfo via a new methodFlags bitfield that parameterizes method requirements. Write extensive conformance tests catching all the (server-side) crashes that were possible.
We should go further and validate schema against the spec, but that is more indirect, more complicated, and potentially slower. For now we adopt this more explicit approach.
Still TODO in a subsequent CL: verify the client side of this with client conformance tests.
Additionally, improve some error messages that were redundant or leaked internal implementation details.
Fixes #195